package com.amigo.online.provider.adv.common;

import com.amigo.online.common.base.security.LocalUser;
import com.amigo.online.common.core.response.StatusCode;
import com.amigo.online.common.param.result.LocalUserInfo;
import com.amigo.online.common.param.result.UserInfo;


import java.util.TimeZone;

public class GlobalController {
    public static UserInfo getNowUser() {
        LocalUserInfo info = LocalUser.getUser();
        if (info == null) {
//            throw new UserException(StatusCode.USER_EXCEPTION);
        }
        UserInfo u = info.getUser();
        if (u.getId() == null || u.getId().intValue() <= 0) {
//            throw new UserException(StatusCode.USER_EXCEPTION);
        }
        return u;
    }

    public static Integer checkPage(Integer page, Integer size) {
        if (page == null || size == null || size.intValue() <= 0 || size.intValue() > 50) {
//            throw new UserException(StatusCode.BAD_REQUEST);
        }
        if (page.intValue() <= 1) {
            page = 1;
        }
        return page;
    }

    public static Long getNowDay0Time() {
        long current = System.currentTimeMillis();//当前时间毫秒数
        long zero = current / (1000 * 3600 * 24) * (1000 * 3600 * 24) - TimeZone.getDefault().getRawOffset();//今天零点零分零秒的毫秒数
        return zero / 1000;
    }

}

